//
//  AppDelegate.m
//  3D_Touch
//
//  Created by Xie Wei on 2019/7/18.
//  Copyright © 2019 Xie Wei. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 首先判断是否支持3D Touch
    if (self.window.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
        // 创建3DTouch模型
        [self setup3DTouch];
    }
    
    return YES;
}

- (void)setup3DTouch {
    /*
     主屏交互(Home Screen Interaction)的实现有两种方式：
     1、通过Info.plist文件静态添加；
     2、通过代码动态添加；
     */
    NSMutableArray *shortcutItems = (NSMutableArray *)[UIApplication sharedApplication].shortcutItems;
    
    UIApplicationShortcutItem *shoreItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"com.xw.test1" localizedTitle:@"test1" localizedSubtitle:@"sub test1" icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd] userInfo:nil];
    [shortcutItems addObject:shoreItem1];
    
    UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"com.xw.test2" localizedTitle:@"test2" localizedSubtitle:@"sub test2" icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"like"] userInfo:nil];
    [shortcutItems addObject:shortItem2];
    
    [UIApplication sharedApplication].shortcutItems = shortcutItems;
}

// 监听主屏交互按钮的点击事件方法
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
    // 不管APP在后台还是进程被杀死，只要通过主屏快捷操作进来的，都会调用这个方法
    NSLog(@"\n\r localizedTitle:%@ \n\r type:%@", shortcutItem.localizedTitle, shortcutItem.type);
}



@end
